package com.andy.blog.admin.controller;

import com.andy.blog.admin.dto.FriendDTO;
import com.andy.blog.admin.service.FriendBusService;
import com.andy.blog.common.annotation.Log;
import com.andy.blog.common.enums.BusinessTypeEnum;
import com.andy.blog.common.page.PageUtilsDTO;
import com.andy.blog.common.reponse.GeneralResponseResult;
import com.andy.blog.dal.vo.FriendVO;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by andy on 2023/7/30 15:25
 */
@RestController
@Api(tags = "友链管理")
public class FriendController {

    @Resource
    private FriendBusService friendBusService;

    /**
     * 获取友链列表
     */
    //@PreAuthorize("@ss.hasPermi('system:sensitive:list')")
    @GetMapping("/portal/friend/list")
    public GeneralResponseResult<List<FriendDTO>> list(FriendVO friendVO) {
        return GeneralResponseResult.success(friendBusService.listFriend(friendVO));
    }

    /**
     * 分页查询
     */
    //@PreAuthorize("@ss.hasPermi('system:sensitive:list')")
    @GetMapping("/friend/listFriendByPage")
    public GeneralResponseResult<PageUtilsDTO<FriendDTO>> listFriendByPage(FriendVO friendVO) {
        return GeneralResponseResult.success(friendBusService.listFriendByPage(friendVO));
    }

    /**
     * 新增友链
     */
    //@PreAuthorize("@ss.hasPermi('system:sensitive:add')")
    @Log(title = "新增友链", businessType = BusinessTypeEnum.INSERT)
    @PostMapping("/friend/addFriend")
    public GeneralResponseResult<Void> add(@Validated @RequestBody FriendVO friendVO) {
        friendBusService.addFriend(friendVO);
        return GeneralResponseResult.success();
    }

    /**
     * 根据id查询
     */
    @PreAuthorize("@ss.hasPermi('system:sensitive:query')")
    @GetMapping(value = "/friend/{id}")
    public GeneralResponseResult<FriendDTO> getDetail(@PathVariable Long id) {
        return GeneralResponseResult.success(friendBusService.selectById(id));
    }

    /**
     * 修改友链
     */
    @PreAuthorize("@ss.hasPermi('system:sensitive:edit')")
    @Log(title = "修改友链", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping("/friend")
    public GeneralResponseResult<Void> edit(@Validated @RequestBody FriendVO friendVO) {
        friendBusService.editFriend(friendVO);
        return GeneralResponseResult.success();
    }

    /**
     * 删除
     */
    //@PreAuthorize("@ss.hasPermi('system:sensitive:remove')")
    //@Log(title = "删除敏感词", businessType = BusinessTypeEnum.DELETE)
    //@DeleteMapping("/{id}")
    //public GeneralResponseResult<Void> remove(@PathVariable Long id) {
    //    sensitiveBusService.deleteById(id);
    //    return GeneralResponseResult.success();
    //}
}
